package com.delong.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.delong.dao.CenterTagsMapper;
import com.delong.dao.DaoHelper;

public class CenterTagsService {

	public void deleteElement(int appId, List<Integer> tagsIds) {
		SqlSession session = null;
		try {
			session = DaoHelper.getSqlSessionFactory().openSession(true);
			CenterTagsMapper mapper = session.getMapper(CenterTagsMapper.class);
			mapper.delElement(appId);
//			System.out.println("change category");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.close();
			}
		}
	}

	public void addElement(int appId, int tagsId) {
		SqlSession session = null;
		try {
			session = DaoHelper.getSqlSessionFactory().openSession(true);
			CenterTagsMapper mapper = session.getMapper(CenterTagsMapper.class);
			mapper.addElement(appId, tagsId);
			System.out.println("change category");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.close();
			}
		}
	}
	
	public List<Integer> getTagsId(int appId)
	{
		SqlSession session = null;
		List<Integer> result=new ArrayList<Integer>();
		try {
			session = DaoHelper.getSqlSessionFactory().openSession(true);
			CenterTagsMapper mapper = session.getMapper(CenterTagsMapper.class);
			result=mapper.selectTagsIds(appId);
			System.out.println("change category");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.close();
			}
		}
		return result;
	}

}
